<%@ LANGUAGE="VBSCRIPT" %>
<%'  ------------------------------------------------------------
  '  mz_propupdate.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.15  $
  '  $Date:   08 Oct 1998 16:04:54  $
  '  $Author:   rurman  $
  '  $Workfile:   mz_propupdate.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>
<!-- #include file="islogon.asp" -->

<%
DebugFlag=0
Dim SubmittedValues(256)
Dim ValidationStatus(256)

ObjType = CInt(Request.Form("Type"))
Ident = Request.Form("Ident")

' ObjType = CInt(Request.QueryString("Type"))
' Ident = Request.QueryString("Ident")

' the Update flag is:
' 0 when ShowHints is TRUE (in this case the property values are not modified and we return to mz_propcontent.asp)
' 1 when Submit current values for Modify properties is TRUE (after saving the new values, we go to mz_viewprop.asp)
Update = Request.Form("UpdateFlag")
if Request.Form("ShowHints") = "on" then
    Session("ShowHints") = 1
else
    Session("ShowHints") = 0
end if
%>
<% 
if DebugFlag then %>
Prop_Update <br>
<%=Ident%>, <%=ObjType%>
<% end if %>
<%
'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
'whether the user has logged on.
'Please see logoncall.asp to see how the Session variable LibraryLogonID is set.
LibraryLogonID = Session("LibraryLogonID")
set LibraryObj = Server.CreateObject("IDMObjects.Library")
LibraryObj.LogonID = LibraryLogonID

On Error Resume Next
set FObj = LibraryObj.GetObject(ObjType, Ident)
if Len(Err.Description) then
    Response.Expires = 0
    Response.Status = "404 Not Found"
    Response.ContentType = "text/plain"
    Response.Write "Document not found: "
    Response.Write Err.Description
    Response.End
end if

set Permissions = FObj.Permissions
set Props = FObj.Properties

Status = "0"
%>

<% 
if DebugFlag then %>
Prop_Update <br>
<% For Each x In Request.Form %>
<%if not (Request.Form(x) = "") then %>
<!-- <INPUT TYPE=hidden name="<%= x %>" value="<%= Request.Form(x) %>"> -->
name="<%= x %>" value="<%= Request.Form(x) %>"<br>
<% end if %>
<% Next %>
<% end if %>

<%
'enumerate through the document Properties - to update its value
for i=1 to Props.Count
    set prop = Props(i)
    set PropDesc = prop.PropertyDescription
    ' assign the property value depends on the property type
    if PropDesc.GetState(Application("idmPropReadOnly")) then
        SubmittedValues(i) = ""
        ValidationStatus(i) = ""
    elseif ObjType = Application("idmObjTypeDocument") and prop.Name = "F_CLOSED" then ' and Props("F_RETENTBASE")
        value = Request.Form(prop.Name)
        SubmittedValues(i) = value
        if value then
            ValidationStatus(i) = "-1"
        else        
            ValidationStatus(i) = "1"
        end if

    ' case of MultiValue property: each value has to be: 
    ' Added - for new values
    ' Removed - for values to be deleted from the existing list ===
    elseif PropDesc.GetState(Application("idmPropMultiValue")) then 
        set MVProp = Prop.Value ' object is a MultipleValues
        delStr = "DELETE_" + UCase(Prop.Name)
        addStr = "ADD_" + UCase(Prop.Name)
        if ( PropDesc.GetState(Application("idmPropMustPick"))) then
          For k=MVProp.Count to 1 Step -1
        %>  
            <% if DebugFlag then %>
            <%= prop.Name%> Delete Val <%= k %><br>
            <% end if %>
        <%
            call MVProp.Remove(CLng(k),1)   ' remove all old settings and reAdd new selection
          next
        else
          For k=Request.Form(delStr).Count to 1 Step -1
            if not (Request.Form(delStr)(k) = "") then
        %>  
            <% if DebugFlag then %>
            <%= prop.Name%> Delete <%=k%>, <%=Request.Form(delStr)(k) %><br>
            <% end if %>
        <%
            call MVProp.Remove(CLng(Request.Form(delStr)(k)),1)
            end if
          next
        end if
        For k=1 to Request.Form(addStr).Count
            if Update then  ' ===========
             if not (Request.Form(addStr)(k) = "") then
                propVal = Request.Form(addStr)(k)
        %>
            <% if DebugFlag then %>
            <%= prop.Name%> Add <%= Request.Form(addStr)(k)%>, <%=propVal%><br>
            <% end if %>
        <%
                if PropDesc.TypeID = Application("idmTypeDate") then

                    isOK = PropDesc.ValidateValue(propVal)

                    %>
            <% if DebugFlag then %>
            <%= prop.Name%> Validate= <%= isOK%>, <%=propVal%><br>
            <% end if %>
                <%
                    call MVProp.Add(propVal)
                else
                call MVProp.Add(Request.Form(addStr)(k))
                end if
             end if
            end if
        next
        
        value = Request.Form(prop.Name)
        SubmittedValues(i) = value ' MultiValue Props are represented as a comma separated list of values
       if Update then ' ===========
        On Error Resume Next
        prop.Value = MVProp
        if Len(Err.Description) = 0 then
            ValidationStatus(i) = "1"
        else
            Status = "-1"
            ValidationStatus(i) = "-1"
            %>
            <% if DebugFlag then %>
            Fail (<%= Err.Description%>): <%= prop.Name%> Val <%= value %><br>
            <% end if %>
        <%
            Response.Write prop.Label+" ["+Err.Description+"]<br>"
        
        end if
       end if

    ' case of single value property with type: must set by ID ===========================
    elseif PropDesc.GetState(Application("idmPropMustSetByID")) then
        value = Request.Form(prop.Name)
        SubmittedValues(i) = value
        lValue = CLng(value)
       if Update then ' ===========
        On Error Resume Next
        prop.Value = lValue
        if Len(Err.Description) = 0 then
        %>
            <% if DebugFlag then %>
            Success <%= prop.Name%> Val <%= value %><br>
            <% end if %>
        <%
            ValidationStatus(i) = "1"
        else
        %>
            <% if DebugFlag then %>
            Fail (<%=Err.Description%>): <%= prop.Name%> Val <%= value %><br>
            <% end if %>
            <%
            Response.Write prop.Label+" ["+Err.Description+"]<br>"
            Status = "-1"
            ValidationStatus(i) = "-1"

        end if
       end if
    else
%>
<% 
if DebugFlag then %>
<%=prop.Name%>=<%=Request.Form(prop.Name)%> <br>
<% end if %>
<%
        value = Request.Form(prop.Name)
        SubmittedValues(i) = value
        ' if PropDesc.GetState(Application("idmPropMustSetByID")) then
        '   value = CInt(value)
        ' end if
       if Update then ' ===========
        On Error Resume Next
        if value = "" then
            prop.Value = NULL
        else 
            if PropDesc.TypeID = Application("idmTypeDate") then
                isOK = PropDesc.ValidateValue(value)
            end if
            prop.Value = value
        end if
        if Len(Err.Description) = 0 then
            ValidationStatus(i) = "1"
        else
            Status = "-1"
            ValidationStatus(i) = "-1"
            %>
            <% if DebugFlag then %>
            Fail (<%= Err.Description%>): <%= prop.Name%> Val <%= value %><br>
            <% end if %>
        <%
            Response.Write prop.Label+" ["+Err.Description+"]<br>"
        
        end if
       end if
    end if
next

Session("SubmittedValues") = SubmittedValues
Session("ValidationStatus") = ValidationStatus

if Update and (not Status) then
    On Error Resume Next
    ' current document object has to be saved so that the new properties values are saved
    FObj.Save

    if Len(Err.Description) > 0 then
        Status = "-1"
        Response.Expires = 0
        ' Response.Status = "404 Not Found"
        Response.ContentType = "text/plain"
         Response.Write "Save Document properties:"
         Response.Write Err.Description
         Response.End
    else
        Status = "1"
    end if
end if

' the Update flag is:
' 0 when ShowHints is TRUE (in this case we return to mz_propcontent.asp)
' 1 when Submit current values for Modify properties is TRUE, and go to mz_viewprop.asp
if Update then
Response.Redirect "mz_viewprops.asp?Type=" + CStr(ObjType) + "&Ident=" + Ident + "&Status=" + Status
else
Response.Redirect "mz_propcontent.asp?Type=" + CStr(ObjType) + "&Ident=" + Ident + "&Update=" + Update + "&Status=" + Status
end if
%>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html">
<TITLE>Property Update</TITLE>
</HEAD>

<body bgcolor="#FFFFFF">

<% if DebugFlag then %>
<%= ObjType %><br>
<%= Ident %><br>
<% for each p in Request.Form %>
    <%= p %> = <%= Request.Form(p) %><br>
<% next
end if %>

</BODY>
</HTML>
